# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
import shutil

from cerbero.tools.libtool import LibtoolLibrary

class Recipe(recipe.Recipe):
    name = 'srt'
    version = '1.4.0'
    url = 'https://github.com/Haivision/srt/archive/v%(version)s.tar.gz'
    tarball_checksum = 'c2ba0bb9382ab42f9eebac831dc021e7da26b2971aaeb30a891dd24297bd929c'
    licenses = [License.MPLv2]
    stype = SourceType.TARBALL
    btype = BuildType.CMAKE
    configure_options = '-DUSE_ENCLIB=openssl -DENABLE_CXX11=OFF'
    # openssl on Linux
    use_system_libs = True

    patches = ['srt/0001-Allow-using-public-API-when-building-with-MSVC.patch']

    files_libs = ['libsrt']
    files_devel = ['include/srt', 'lib/pkgconfig/srt.pc']

    def prepare(self):
        if self.config.target_platform != Platform.LINUX or self.config.cross_compiling():
            self.deps.append('openssl')
        if self.config.target_platform == Platform.ANDROID:
            self.append_env('CXXFLAGS', '-frtti', '-fexceptions')
            self.configure_options += ' -DUSE_GNUSTL=ON'
            self.deps.append('gnustl')

    def post_install(self):
        libtool_la = LibtoolLibrary('srt', None, None, None, self.config.libdir,
                self.config.target_platform, deps=['ssl', 'crypto'])
        libtool_la.save()
        super().post_install()
